package topcoder;

import java.util.Deque;
import java.util.LinkedList;

public class GooseInZooDivTwo {

	int binom(int n) {
		int[] b = new int[n+1];
		
		b[0] = 1;
		for (int i = 1; i <= n; ++i) {
			b[i] = 1;
			for (int j = i - 1; j > 0; --j)
				b[j] += b[j - 1];
			for (int j = i - 1; j > 0; --j)
				b[j] = b[j] % 1000000007;
		}
		
		int sum = 0;
		for (int i = 1; i <= n; i++) {
			sum += b[i];
		}
		return sum;
	}
	
	void dfs(int x, int y, int d, int maxd, boolean[][] visited, String[] S, int c, char[][] M) {
		if ( x < 0 || y < 0 || y >= S.length || x >= S[y].length())
			return;
		if ( visited[y][x] ) 
			return;
		if ( d > maxd )
			return;
		
		if ( S[y].charAt(x) == 'v' ) {
			d = 0;
			visited[y][x] = true;
			M[y][x] = (char) (48 + c % 75);
		}
		
		
		dfs( x+1, y, d+1, maxd, visited, S, c, M);
		dfs( x-1, y, d+1, maxd, visited, S, c, M);
		dfs( x, y+1, d+1, maxd, visited, S, c, M);
		dfs( x, y-1, d+1, maxd, visited, S, c, M);
	}
	
	void bfs(int x, int y, int maxd, boolean[][] visited, boolean[][] local, String[] S, int c, char[][] M) {
		Deque<Integer> Qx = new LinkedList<Integer>();
		Deque<Integer> Qy = new LinkedList<Integer>();
		Deque<Integer> D = new LinkedList<Integer>();
		
		visited[y][x] = true;
		Qx.add(x);
		Qy.add(y);
		D.add(0);
		
		M[y][x] = (char) (48 + c % 75);
		
		while (!Qx.isEmpty()) {
			
			int d = D.remove();
			int vx = Qx.remove();
			int vy = Qy.remove();
			
			bfsChild(vx + 1, vy, d + 1, maxd, visited, local, S, Qx, Qy, D, c, M);
			bfsChild(vx - 1, vy, d + 1, maxd, visited, local, S, Qx, Qy, D, c, M);
			bfsChild(vx, vy + 1, d + 1, maxd, visited, local, S, Qx, Qy, D, c, M);
			bfsChild(vx, vy - 1, d + 1, maxd, visited, local, S, Qx, Qy, D, c, M);
		}
	}
	
	void bfsChild(int x, int y, int d, int maxd, boolean[][] visited, boolean[][] local, 
			String[] S, Deque<Integer> Qx, Deque<Integer> Qy, Deque<Integer> D, int c, char[][] M) {
		
		if ( x < 0 || y < 0 || y >= S.length || x >= S[y].length())
			return;
		if ( local[y][x] || visited[y][x]) 
			return;
		if ( d > maxd )
			return;
		
		
		
		if ( S[y].charAt(x) == 'v' ){
			d = 0;	
			M[y][x] = (char) (48 + c % 75);
			visited[y][x] = true;
			
			for (int i = 0; i < S.length; i++) {
				for(int j = 0; j < S[y].length(); j++)
					local[i][j] = false;
			}
		}
		
		local[y][x] = true;
		Qx.add(x);
		Qy.add(y);
		D.add(d);
	}
	
	public int count(String[] S, int maxd) {
		 
		int c = 0;
		boolean[][] visited = new boolean[50][50];
		
		char[][] M = new char[S.length][S.length];
		
		for (int y = 0; y < S.length; y++) {
			for(int x = 0; x < S[y].length(); x++)
				M[y][x] = '.';
		}
		
		for (int y = 0; y < S.length; y++) {
		
			for(int x = 0; x < S[y].length(); x++) {
				
				if (visited[y][x]) continue;
				
				if (S[y].charAt(x) == 'v') {
					c += 1;
					//bfs(x, y, maxd, visited, new boolean[50][50], S, c, M);
					dfs(x, y, 0, maxd, visited, S, c, M);
				}
			}
			
		}
		
//		for (int y = 0; y < S.length; y++) {
//			for(int x = 0; x < S[y].length(); x++)
//				System.out.print(M[y][x]);
//			System.out.println();
//		}
		
		return (int)((Math.pow(2, c)-1) % 1000000007);
		
	}
	
	
	public static void main(String[] args) {
		String[] S = new String[]
				{"v.v..................v............................"
				,".v......v..................v.....................v"
				,"..v.....v....v.........v...............v......v..."
				,".........vvv...vv.v.........v.v..................v"
				,".....v..........v......v..v...v.......v..........."
				,"...................vv...............v.v..v.v..v..."
				,".v.vv.................v..............v............"
				,"..vv.......v...vv.v............vv.....v.....v....."
				,"....v..........v....v........v.......v.v.v........"
				,".v.......v.............v.v..........vv......v....."
				,"....v.v.......v........v.....v.................v.."
				,"....v..v..v.v..............v.v.v....v..........v.."
				,"..........v...v...................v..............v"
				,"..v........v..........................v....v..v..."
				,"....................v..v.........vv........v......"
				,"..v......v...............................v.v......"
				,"..v.v..............v........v...............vv.vv."
				,"...vv......v...............v.v..............v....."
				,"............................v..v.................v"
				,".v.............v.......v.........................."
				,"......v...v........................v.............."
				,".........v.....v..............vv.................."
				,"................v..v..v.........v....v.......v...."
				,"........v.....v.............v......v.v............"
				,"...........v....................v.v....v.v.v...v.."
				,"...........v......................v...v..........."
				,"..........vv...........v.v.....................v.."
				,".....................v......v............v...v...."
				,".....vv..........................vv.v.....v.v....."
				,".vv.......v...............v.......v..v.....v......"
				,"............v................v..........v....v...."
				,"................vv...v............................"
				,"................v...........v........v...v....v..."
				,"..v...v...v.............v...v........v....v..v...."
				,"......v..v.......v........v..v....vv.............."
				,"...........v..........v........v.v................"
				,"v.v......v................v....................v.."
				,".v........v................................v......"
				,"............................v...v.......v........."
				,"........................vv.v..............v...vv.."
				,".......................vv........v.............v.."
				,"...v.............v.........................v......"
				,"....v......vv...........................v........."
				,"....vv....v................v...vv..............v.."
				,".................................................."
				,"vv........v...v..v.....v..v..................v...."
				,".........v..............v.vv.v.............v......"
				,".......v.....v......v...............v............."
				,"..v..................v................v....v......"
				,".....v.....v.....................v.v......v......."};
		
		GooseInZooDivTwo r = new GooseInZooDivTwo();
		System.out.println(r.count(S, 3));
	}
	
}
